package com.activemanager.healthGadget;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.activemanager.myHealthProfile.Q1MainActivity;
import com.example.android.navigationdrawerexample.R;


import android.app.Dialog;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Parcelable;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.util.Log;
import android.view.Display;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;

public class FootReader extends FragmentActivity {
	
	private ViewPager vp;
	
	private MyPagerAdapterAssistant myAdapter;
	
	private List<View> vessel = new ArrayList<View>();

	private View view1, view2, view3,view4, view5, view6;
	ArrayAdapter<String> arraydp;

	ViewGroup group;
	Animation fadeInAnimation;
	Animation fadeOutAnimation;
	RelativeLayout bgLinearLayout;
	boolean redunct = true;

	AnimationSet animationSet;
	AlphaAnimation alphaAnimation1, alphaAnimation2;

	ImageView[] imageView_Sign;
	ViewGroup mainView = null;
	ImageView SB2_imageView4 = null, S1_imageView2 = null,
			S1_imageView3 = null;
	Bitmap bitmapNSelected, bitmapSelected;
	
	ImageView img42 ;
	BitmapFactory.Options opt;
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		mainView = (ViewGroup) this.getLayoutInflater().inflate(
				R.layout.activity_main_pageview_assistant, null);
		setContentView(mainView);

		animationSet = new AnimationSet(true);
		alphaAnimation2 = new AlphaAnimation(1, 0);
		alphaAnimation2.setDuration(500);
		alphaAnimation2.setStartOffset(500);

		alphaAnimation1 = new AlphaAnimation(0, 1);
		alphaAnimation1.setDuration(500);

		animationSet.addAnimation(alphaAnimation1);
		animationSet.addAnimation(alphaAnimation2);

		animationSet.setFillBefore(false);
		animationSet.setFillAfter(true);

		init();
		T2Action(view1);
		T2Action(view4);
		t3Action(view2);
		t3Action(view5);
		t4Action(view3);
		t4Action(view6);
		
		ImageView img_home = (ImageView) findViewById(R.id.imageView);
		img_home.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				finish();
			}});
		
		
		Button btn_share = (Button) findViewById(R.id.btn_share);
		btn_share.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View arg0) {
				final Dialog dialog = new Dialog(FootReader.this,
						R.style.MyDialog);
				
				dialog.setContentView(R.layout.p7_share);
				
				final BitmapFactory.Options opt = new BitmapFactory.Options();
				opt.inPreferredConfig = Bitmap.Config.RGB_565;
				opt.inPurgeable = true;
				opt.inInputShareable = true;
				
				final LinearLayout img = (LinearLayout) dialog.findViewById(R.id.linearLayout);
//				InputStream is = getResources().openRawResource(
//						R.drawable.u165_normal);
//				Bitmap bit = BitmapFactory.decodeStream(is, null, opt);
//				img.setBackgroundDrawable(new BitmapDrawable(bit));
				img.setBackgroundResource(R.drawable.bg_for_popup_54);
				
				
				dialog.show();
				Button btnDialog_cancel = (Button) dialog
						.findViewById(R.id.button1);
				btnDialog_cancel.setOnClickListener(new OnClickListener() {

					public void onClick(View v) {
						dialog.dismiss();	
					}
				});
				Window dialogWindow = dialog.getWindow();
				WindowManager m = getWindowManager();
				Display d = m.getDefaultDisplay();
				WindowManager.LayoutParams p = dialogWindow.getAttributes();
				p.height = (int) (d.getHeight() * 0.765);
				p.width = (int) (d.getWidth() * 0.95);
				dialogWindow.setAttributes(p);
				
				String[] mFrom = new String[] { "profile_img", "profile_item" };
				String[] profileTitle = { "Sina Weibo", "Tencent Weibo", "We Chat",
						"QQ", "KaiXin", "Email" };
				int[] mTo = new int[] { R.id.profile_img, R.id.profile_item };
				List<Map<String, Object>> mList = new ArrayList<Map<String, Object>>();
				Map<String, Object> mMap = null;
				for (int i = 0; i < profileTitle.length; i++) {
					mMap = new HashMap<String, Object>();
					
					int drawable = getResources().getIdentifier(
							"share_to_" + (1 + i), "drawable",
							FootReader.this.getPackageName());
					mMap.put("profile_img", drawable);
					mMap.put("profile_item", profileTitle[i]);
					mList.add(mMap);
				
					
				}
				final ListView mListView = (ListView) dialog.findViewById(R.id.list_view);
				SimpleAdapter mAdapter = new SimpleAdapter(FootReader.this, mList,	R.layout.drawer_list_item_for_sports, mFrom, mTo);
				mListView.setAdapter(mAdapter);
				mListView.setOnItemClickListener(new OnItemClickListener(){

					@Override
					public void onItemClick(AdapterView<?> arg0, View arg1,
							int pos, long arg3) {
						// TODO Auto-generated method stub
							dialog.dismiss();
							final Dialog dialog1 = new Dialog(FootReader.this,
									R.style.MyDialog);
							dialog1.setContentView(R.layout.onloading_error);
							Window dialogWindow = dialog1.getWindow();
							WindowManager m = getWindowManager();
							Display d = m.getDefaultDisplay();
							WindowManager.LayoutParams p = dialogWindow.getAttributes();
							p.height = (int) (d.getHeight() * 0.47);
							p.width = (int) (d.getWidth() * 0.95);
							dialogWindow.setAttributes(p);
							final RelativeLayout img = (RelativeLayout) dialog1.findViewById(R.id.d_share_layout);
							final TextView tv = (TextView) dialog1.findViewById(R.id.textView1);
//							InputStream is = getResources().openRawResource(
//									R.drawable.u165_normal);
//							Bitmap bit = BitmapFactory.decodeStream(is, null, opt);
//							img.setBackgroundDrawable(new BitmapDrawable(bit));
							img.setBackgroundResource(R.drawable.bg_for_popup_54);
							dialog1.show();
								new Handler().postDelayed(new Runnable(){
								
								@Override
								public void run() {
									tv.setText("The information has been\n   successfully shared.");
									new Handler().postDelayed(new Runnable(){
										
										@Override
										public void run() {
											dialog1.dismiss();
										}}, 1000);
									
								}}, 800);
						

					}
					
				});

			
			}
			});
	}

	

	public void init() {
		// ���xml
		view1 = getLayoutInflater().inflate(R.layout.t2, null);
		view2 = this.getLayoutInflater().inflate(R.layout.t3, null);
		view3 = this.getLayoutInflater().inflate(R.layout.t4, null);
		view4 = getLayoutInflater().inflate(R.layout.t2, null);
		view5 = this.getLayoutInflater().inflate(R.layout.t3, null);
		view6 = this.getLayoutInflater().inflate(R.layout.t4, null);

		initPic();

		vessel.add(view1);
		vessel.add(view2);
		vessel.add(view3);
		vessel.add(view4);
		vessel.add(view5);
		vessel.add(view6);

		vp = (ViewPager) findViewById(R.id.viewpagerLayout_assistant);
		bgLinearLayout = (RelativeLayout) findViewById(R.id.bgLinearLayout);
		myAdapter = new MyPagerAdapterAssistant();
		vp.setAdapter(myAdapter);
		// ������ʼĬ�ϵ�ֵΪ0
		// vp.setCurrentItem(0);
		vp.setOnPageChangeListener(new MyOnPageChangeListener());

	}
	
	
	private void T2Action(View view){
		final BitmapFactory.Options opt = new BitmapFactory.Options();
		opt.inPreferredConfig = Bitmap.Config.RGB_565;
		opt.inPurgeable = true;
		opt.inInputShareable = true;
		
	ImageView img2 = (ImageView) view.findViewById(R.id.imageView1);
	InputStream is2 = getResources().openRawResource(R.drawable.u33_normal);
	Bitmap bit2 = BitmapFactory.decodeStream(is2, null, opt);
//	img2.setImageResource(R.drawable.u33_normal);

	final ImageView img3 = (ImageView) view.findViewById(R.id.imageView2);
	InputStream is3 = getResources().openRawResource(R.drawable.u35_normal);
	Bitmap bit3 = BitmapFactory.decodeStream(is3, null, opt);
//	img3.setImageBitmap(bit3);
}

	private void initPic() {
		final BitmapFactory.Options opt = new BitmapFactory.Options();
		opt.inPreferredConfig = Bitmap.Config.RGB_565;
		opt.inPurgeable = true;
		opt.inInputShareable = true;

		LinearLayout img_bg = (LinearLayout) findViewById(R.id.relativeLayout1);
//		InputStream is_bg = getResources().openRawResource(
//				R.drawable.bg_540);
//		Bitmap bit_bg = BitmapFactory.decodeStream(is_bg, null, opt);
//		img_bg.setBackgroundDrawable(new BitmapDrawable(bit_bg));
		img_bg.setBackgroundResource(R.drawable.bg_540);

		

		final Animation fadeInAnimation = AnimationUtils.loadAnimation(
				FootReader.this, R.anim.fade);

		

		InputStream input1 = getResources().openRawResource(R.drawable.select);
		bitmapSelected = BitmapFactory.decodeStream(input1, null, opt);
		InputStream input2 = getResources().openRawResource(
				R.drawable.select_normal);
		bitmapNSelected = BitmapFactory.decodeStream(input2, null, opt);
		group = (ViewGroup) findViewById(R.id.viewGroup);
		imageView_Sign = new ImageView[3];
		for (int i = 0; i < 3; i++) {
			imageView_Sign[i] = new ImageView(FootReader.this);
			LinearLayout.LayoutParams layout = new LinearLayout.LayoutParams(
					LinearLayout.LayoutParams.WRAP_CONTENT,
					LinearLayout.LayoutParams.WRAP_CONTENT);
			layout.setMargins(20, 0, 20, 0);
			imageView_Sign[i].setLayoutParams(layout);
			if (i == 0) {
				imageView_Sign[i].setImageBitmap(bitmapSelected);
			} else {
				imageView_Sign[i].setImageBitmap(bitmapNSelected);
			}
			group.addView(imageView_Sign[i]);
		}
		group.setAnimation(animationSet);

	}

	// ������
	class MyPagerAdapterAssistant extends PagerAdapter {

		public void destroyItem(View arg0, int arg1, Object arg2) {
			if (arg1 >= vessel.size() - 1) {
				int newPosition = arg1 % vessel.size();
				arg1 = newPosition;
			}
			((ViewPager) arg0).removeView(vessel.get(arg1));
		}

		public void finishUpdate(View arg0) {
		}

		public int getCount() {
			return Integer.MAX_VALUE;
		}

		public Object instantiateItem(View arg0, int arg1) {
			if (arg1 >= vessel.size() - 1) {
				int newPosition = arg1 % vessel.size();
				arg1 = newPosition;
			}
			((ViewPager) arg0).addView(vessel.get(arg1), 0);
			return vessel.get(arg1);
		}

		public boolean isViewFromObject(View arg0, Object arg1) {
			return arg0 == (arg1);
		}

		public void restoreState(Parcelable arg0, ClassLoader arg1) {
		}

		public Parcelable saveState() {
			return null;
		}

		@Override
		public void startUpdate(View arg0) {
			Log.d("k", "startUpdate");
		}

	}

	public class MyOnPageChangeListener implements OnPageChangeListener {

		@Override
		public void onPageSelected(final int arg0) {
			int ii = arg0;
			for (int i = 0; i < imageView_Sign.length; i++) {
				imageView_Sign[arg0 % imageView_Sign.length]
						.setImageBitmap(bitmapSelected);

				if (arg0 != i) {
					imageView_Sign[i % imageView_Sign.length]
							.setImageBitmap(bitmapNSelected);
				}
			}
			AnimationSet animationSet = new AnimationSet(true);
			AlphaAnimation alphaAnimation1 = new AlphaAnimation(0, 1);
			alphaAnimation1.setDuration(500);
			animationSet.addAnimation(alphaAnimation1);

			AlphaAnimation alphaAnimation2 = new AlphaAnimation(1, 0);
			alphaAnimation2.setDuration(500);
			alphaAnimation2.setStartOffset(500);
			animationSet.addAnimation(alphaAnimation2);
			animationSet.setFillBefore(false);
			animationSet.setFillAfter(true);
			group.setAnimation(animationSet);
			new Handler().postDelayed(new Runnable() {

				@Override
				public void run() {
			if(arg0 ==1 || arg0 == 4){
				final BitmapFactory.Options opt = new BitmapFactory.Options();
				opt.inPreferredConfig = Bitmap.Config.RGB_565;
				opt.inPurgeable = true;
				opt.inInputShareable = true;
				
				ImageView img22 = (ImageView) view2.findViewById(R.id.imageView1);
				final ImageView img23 = (ImageView) view2.findViewById(R.id.imageView2);
				InputStream is22 = getResources().openRawResource(
						R.drawable.foot_update_11);
				Bitmap bit22 = BitmapFactory.decodeStream(is22, null, opt);

				img22.setBackgroundDrawable(new BitmapDrawable(bit22));
				img22.setAnimation(fadeInAnimation);
				new Handler().postDelayed(new Runnable() {

					@Override
					public void run() {
						final ImageView img3 = (ImageView) view2.findViewById(R.id.imageView2);
						InputStream is3 = getResources().openRawResource(
								R.drawable.foot_update_09);
						Bitmap bit3 = BitmapFactory.decodeStream(is3, null, opt);
						img3.setBackgroundDrawable(new BitmapDrawable(bit3));
					}
				}, 500);
				
				ImageView img42 = (ImageView) view5.findViewById(R.id.imageView1);
				final ImageView img43 = (ImageView) view5.findViewById(R.id.imageView2);
				InputStream is42 = getResources().openRawResource(
						R.drawable.foot_update_11);
				Bitmap bit42 = BitmapFactory.decodeStream(is42, null, opt);

				img42.setBackgroundDrawable(new BitmapDrawable(bit42));
				img42.setAnimation(fadeInAnimation);
				new Handler().postDelayed(new Runnable() {

					@Override
					public void run() {
						final ImageView img3 = (ImageView) view5.findViewById(R.id.imageView2);
						InputStream is3 = getResources().openRawResource(
								R.drawable.foot_update_09);
						Bitmap bit3 = BitmapFactory.decodeStream(is3, null, opt);
						img3.setBackgroundDrawable(new BitmapDrawable(bit3));
					}
				}, 500);
			}
				}}, 300);
			
			
		}

		@Override
		public void onPageScrolled(int arg0, float arg1, int arg2) {
		}

		@Override
		public void onPageScrollStateChanged(int arg0) {
		}
	}
	
	private void t4Action(final View view) {
		// TODO Auto-generated method stub
		RelativeLayout viewLayout = (RelativeLayout) view.findViewById(R.id.activityLayout);
		RelativeLayout bodyLayout = (RelativeLayout) view.findViewById(R.id.typeLayout);
		img42 = (ImageView) view.findViewById(R.id.imageView1);
		 InputStream is2 = getResources().openRawResource(
		 R.drawable.footupdate2_06);
		 Bitmap bit2 = BitmapFactory.decodeStream(is2, null, opt);
		img42.setBackgroundDrawable(new BitmapDrawable(bit2));
		
		viewLayout.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				final Dialog dialog = new Dialog(FootReader.this,
						R.style.MyDialog);
				final BitmapFactory.Options opt = new BitmapFactory.Options();
				opt.inPreferredConfig = Bitmap.Config.RGB_565;
				opt.inPurgeable = true;
				opt.inInputShareable = true;

				dialog.setContentView(R.layout.p7);
				final LinearLayout img = (LinearLayout) dialog
						.findViewById(R.id.linearLayout);
//				InputStream is = getResources().openRawResource(R.drawable.u165_normal);
//				Bitmap bit = BitmapFactory.decodeStream(is, null, opt);
//				img.setBackgroundDrawable(new BitmapDrawable(bit));
				img.setBackgroundResource(R.drawable.bg_for_popup_54);
				
				final TextView textview = (TextView) view
						.findViewById(R.id.textView5);
				
				
				final TextView tv = (TextView) dialog
						.findViewById(R.id.textView1);
				tv.setText("VIEW");
				dialog.show();
				Window dialogWindow = dialog.getWindow();
				WindowManager m = getWindowManager();
				Display d = m.getDefaultDisplay();
				WindowManager.LayoutParams p = dialogWindow.getAttributes();
				p.height = (int) (d.getHeight() * 0.765);
				p.width = (int) (d.getWidth() * 0.95);
				dialogWindow.setAttributes(p);

				String[] mFrom = new String[] {"choose_item"};
				int[]  mTo =new int[] {  R.id.profile_item};
				String[] chooseTitle = { "Bottom up", "Top down" };
				List mList = new ArrayList<String>();
				for (int i = 0; i < chooseTitle.length; i++) {
					Map<String, Object> mMap = new HashMap<String,Object>();
					mMap.put("choose_item", chooseTitle[i]);
					mList.add(mMap);
				}
				final ListView mListView = (ListView) dialog.findViewById(R.id.list_view);
				SimpleAdapter mAdapter = new SimpleAdapter(FootReader.this, mList,	R.layout.pure_text_list_item, mFrom, mTo);
				mListView.setAdapter(mAdapter);
				mListView.setOnItemClickListener(new OnItemClickListener(){

					@Override
					public void onItemClick(AdapterView<?> arg0, View arg1,
							int pos, long arg3) {
						// TODO Auto-generated method stub
						HashMap<String,String> map = (HashMap<String, String>) mListView.getItemAtPosition(pos);
						String text = map.get("choose_item");
						textview.setText(text);
						if(pos==0){
							img42.setImageResource(R.drawable.footupdate2_06);
						}else{
							img42.setImageResource(R.drawable.footupdate2_03);
						}
						
						dialog.dismiss();
					}
					
				});
				
				
				Button btn_cancel = (Button) dialog
						.findViewById(R.id.button1);
				btn_cancel.setOnClickListener(new OnClickListener(){

					@Override
					public void onClick(View arg0) {
						// TODO Auto-generated method stub
						dialog.dismiss();
					}
				});
				
			}
		});
		
		bodyLayout.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				final Dialog dialog = new Dialog(FootReader.this,
						R.style.MyDialog);
				final BitmapFactory.Options opt = new BitmapFactory.Options();
				opt.inPreferredConfig = Bitmap.Config.RGB_565;
				opt.inPurgeable = true;
				opt.inInputShareable = true;

				dialog.setContentView(R.layout.p7);
				final LinearLayout img = (LinearLayout) dialog
						.findViewById(R.id.linearLayout);
//				InputStream is = getResources().openRawResource(R.drawable.u165_normal);
//				Bitmap bit = BitmapFactory.decodeStream(is, null, opt);
//				img.setBackgroundDrawable(new BitmapDrawable(bit));
				img.setBackgroundResource(R.drawable.bg_for_popup_54);
				
				final TextView textview = (TextView) view
						.findViewById(R.id.textView6);
				
				
				final TextView tv = (TextView) dialog
						.findViewById(R.id.textView1);
				tv.setText("BODY PART REFLECTED");
				dialog.show();
				Window dialogWindow = dialog.getWindow();
				WindowManager m = getWindowManager();
				Display d = m.getDefaultDisplay();
				WindowManager.LayoutParams p = dialogWindow.getAttributes();
				p.height = (int) (d.getHeight() * 0.765);
				p.width = (int) (d.getWidth() * 0.95);
				dialogWindow.setAttributes(p);

				String[] mFrom = new String[] {"choose_item"};
				int[]  mTo =new int[] {  R.id.profile_item};
				String[] chooseTitle = { "1 - Sinus", "2 - Neck","3 - Trachea", "4 - Ear", "5 - Eye", "6 - Vocal Cords", "7 - lung",
						"8 - Shoulder", "9 - Throid", "10 - Diaphragm", "11 - Heart", "12 - Spleen", "13 - Pancreas", "14 - Adrenal Gland", 
						"15 - Kidney", "16 - Transverse Colon", "17 - Bladder", "18 - Small Intentine", "19 - Descending Colon", 
						"20 - Sciatic", "21 - Knee", "22 - Thigh", "23 - Hip", "24 - Gallbladder", "25 - Liver", "26 - Stomach"};
				List mList = new ArrayList<String>();
				for (int i = 0; i < chooseTitle.length; i++) {
					Map<String, Object> mMap = new HashMap<String,Object>();
					mMap.put("choose_item", chooseTitle[i]);
					mList.add(mMap);
				}
				final ListView mListView = (ListView) dialog.findViewById(R.id.list_view);
				SimpleAdapter mAdapter = new SimpleAdapter(FootReader.this, mList,	R.layout.pure_text_list_item, mFrom, mTo);
				mListView.setAdapter(mAdapter);
				mListView.setOnItemClickListener(new OnItemClickListener(){

					@Override
					public void onItemClick(AdapterView<?> arg0, View arg1,
							int pos, long arg3) {
						// TODO Auto-generated method stub
						if(pos == 8 ){
						HashMap<String,String> map = (HashMap<String, String>) mListView.getItemAtPosition(pos);
						String text = map.get("choose_item");
						textview.setText(text);
						dialog.dismiss();
						img42.setImageResource(R.drawable.footupdate2_09);
						}
					}
					
				});
				
				
				Button btn_cancel = (Button) dialog
						.findViewById(R.id.button1);
				btn_cancel.setOnClickListener(new OnClickListener(){

					@Override
					public void onClick(View arg0) {
						// TODO Auto-generated method stub
						dialog.dismiss();
					}
				});
				
			}
		});
	}

	private void t3Action(final View view) {
		// TODO Auto-generated method stub
		
		final BitmapFactory.Options opt = new BitmapFactory.Options();
		opt.inPreferredConfig = Bitmap.Config.RGB_565;
		opt.inPurgeable = true;
		opt.inInputShareable = true;
		
		
		RelativeLayout typeLayout = (RelativeLayout) view.findViewById(R.id.typeLayout);
		RelativeLayout activityLayout = (RelativeLayout) view.findViewById(R.id.activityLayout);
		
//		ImageView img22 = (ImageView) view.findViewById(R.id.imageView1);
//		final ImageView img23 = (ImageView) view.findViewById(R.id.imageView2);
//		InputStream is22 = getResources().openRawResource(
//				R.drawable.foot_update_11);
//		Bitmap bit22 = BitmapFactory.decodeStream(is22, null, opt);
//
//		img22.setBackgroundDrawable(new BitmapDrawable(bit22));
//		img22.setAnimation(fadeInAnimation);
//		new Handler().postDelayed(new Runnable() {
//
//			@Override
//			public void run() {
//				final ImageView img3 = (ImageView) view.findViewById(R.id.imageView2);
//				InputStream is3 = getResources().openRawResource(
//						R.drawable.foot_update_09);
//				Bitmap bit3 = BitmapFactory.decodeStream(is3, null, opt);
//				img3.setBackgroundDrawable(new BitmapDrawable(bit3));
//			}
//		}, 2000);

		
		activityLayout.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				final Dialog dialog = new Dialog(FootReader.this,
						R.style.MyDialog);
				final BitmapFactory.Options opt = new BitmapFactory.Options();
				opt.inPreferredConfig = Bitmap.Config.RGB_565;
				opt.inPurgeable = true;
				opt.inInputShareable = true;

				dialog.setContentView(R.layout.p30);
				final LinearLayout img = (LinearLayout) dialog
						.findViewById(R.id.linearLayout);
//				InputStream is = getResources().openRawResource(R.drawable.u165_normal);
//				Bitmap bit = BitmapFactory.decodeStream(is, null, opt);
//				img.setBackgroundDrawable(new BitmapDrawable(bit));
				img.setBackgroundResource(R.drawable.bg_for_popup_54);
				
				final TextView textview = (TextView) view
						.findViewById(R.id.textView5);
				
				
				final TextView tv = (TextView) dialog
						.findViewById(R.id.textView1);
				tv.setText("ACTIVITY");
				dialog.show();
				Window dialogWindow = dialog.getWindow();
				WindowManager m = getWindowManager();
				Display d = m.getDefaultDisplay();
				WindowManager.LayoutParams p = dialogWindow.getAttributes();
				p.height = (int) (d.getHeight() * 0.765);
				p.width = (int) (d.getWidth() * 0.95);
				dialogWindow.setAttributes(p);

				String[] mFrom = new String[] { "profile_img", "profile_item" };
				String[] profileTitle = { "Walking", "Jogging", "Cycling",
						"Badminton" };
				String[] resName = new String[]{"choose_u159_normal","choose_u155_normal","choose_u158_normal","choose_u156_normal"};
				int[] mTo = new int[] { R.id.profile_img, R.id.profile_item };
				List<Map<String, Object>> mList = new ArrayList<Map<String, Object>>();
				Map<String, Object> mMap = null;
				for (int i = 0; i < profileTitle.length; i++) {
					mMap = new HashMap<String, Object>();
					int drawable = getResources().getIdentifier(
							resName[i], "drawable",
							getPackageName());
					mMap.put("profile_img", drawable);
					mMap.put("profile_item", profileTitle[i]);
					mList.add(mMap);
				}
				final ListView mListView = (ListView) dialog
						.findViewById(R.id.list_view);
				SimpleAdapter mAdapter = new SimpleAdapter(FootReader.this,
						mList, R.layout.drawer_list_item_for_sports, mFrom, mTo);
				mListView.setAdapter(mAdapter);
				mListView.setOnItemClickListener(new OnItemClickListener(){

					@Override
					public void onItemClick(AdapterView<?> arg0, View arg1,
							int pos, long arg3) {
						// TODO Auto-generated method stub
						if(pos!=0 && pos != 4){
						HashMap<String,String> map = (HashMap<String, String>) mListView.getItemAtPosition(pos);
						String text = map.get("profile_item");
						textview.setText(text);
						dialog.dismiss();
						}
					}
					
				});
				
				
				Button btn_cancel = (Button) dialog
						.findViewById(R.id.button1);
				btn_cancel.setOnClickListener(new OnClickListener(){

					@Override
					public void onClick(View arg0) {
						// TODO Auto-generated method stub
						dialog.dismiss();
					}
				});
				
			}
		});
		
		typeLayout.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				final Dialog dialog = new Dialog(FootReader.this,
						R.style.MyDialog);
				final BitmapFactory.Options opt = new BitmapFactory.Options();
				opt.inPreferredConfig = Bitmap.Config.RGB_565;
				opt.inPurgeable = true;
				opt.inInputShareable = true;

				dialog.setContentView(R.layout.p7);
				final LinearLayout img = (LinearLayout) dialog
						.findViewById(R.id.linearLayout);
//				InputStream is = getResources().openRawResource(R.drawable.u165_normal);
//				Bitmap bit = BitmapFactory.decodeStream(is, null, opt);
//				img.setBackgroundDrawable(new BitmapDrawable(bit));
				img.setBackgroundResource(R.drawable.bg_for_popup_54);
				
				final TextView textview = (TextView) view
						.findViewById(R.id.textView6);
				
				
				final TextView tv = (TextView) dialog
						.findViewById(R.id.textView1);
				tv.setText("DATA TYPE");
				dialog.show();
				Window dialogWindow = dialog.getWindow();
				WindowManager m = getWindowManager();
				Display d = m.getDefaultDisplay();
				WindowManager.LayoutParams p = dialogWindow.getAttributes();
				p.height = (int) (d.getHeight() * 0.765);
				p.width = (int) (d.getWidth() * 0.95);
				dialogWindow.setAttributes(p);

				String[] mFrom = new String[] {"choose_item"};
				int[]  mTo =new int[] {  R.id.profile_item};
				String[] chooseTitle = { "Mean plantar pressure", "Peak pantar pressure", "Pressure - Time Intetral", "Force - Time Intergral", "Force distribution" };
				List mList = new ArrayList<String>();
				for (int i = 0; i < chooseTitle.length; i++) {
					Map<String, Object> mMap = new HashMap<String,Object>();
					mMap.put("choose_item", chooseTitle[i]);
					mList.add(mMap);
				}
				final ListView mListView = (ListView) dialog.findViewById(R.id.list_view);
				SimpleAdapter mAdapter = new SimpleAdapter(FootReader.this, mList,	R.layout.pure_text_list_item, mFrom, mTo);
				mListView.setAdapter(mAdapter);
				mListView.setOnItemClickListener(new OnItemClickListener(){

					@Override
					public void onItemClick(AdapterView<?> arg0, View arg1,
							int pos, long arg3) {
						// TODO Auto-generated method stub
						if(pos!=0 && pos != 4){
						HashMap<String,String> map = (HashMap<String, String>) mListView.getItemAtPosition(pos);
						String text = map.get("choose_item");
						textview.setText(text);
						dialog.dismiss();
						}
					}
					
				});
				
				
				Button btn_cancel = (Button) dialog
						.findViewById(R.id.button1);
				btn_cancel.setOnClickListener(new OnClickListener(){

					@Override
					public void onClick(View arg0) {
						// TODO Auto-generated method stub
						dialog.dismiss();
					}
				});
				
			}
		});
	}

}
